<script lang="ts" setup name="infrastructureRelation">
import { getListByConditionsWithPage, urls } from '@/index';
import type {
  DialogModel,
  InfrastructureRelation,
  InfrastructureRelationQueryCondition
} from '@/index.d';
import { useRequest } from 'vue-request';
import DetailDialog from './DetailDialog.vue';
const title = '相关方';
const queryCondition = reactive<InfrastructureRelationQueryCondition>({
  deleted: false,
  change: false,
  currentPage: 1,
  pageSize: 20
});

const resetQueryCondition = () => {
  queryCondition.currentPage = 1;
  queryCondition.pageSize = 20;
  queryCondition.deleted = false;
  delete queryCondition.addressProvince;
  delete queryCondition.name;
};

const {
  data: getInfrastructureRelationListData,
  run: getInfrastructureRelationListRun,
  loading: getInfrastructureRelationListLoading
} = useRequest(() => getListByConditionsWithPage(urls.infrastructureRelation, queryCondition));

const handleResetQuery = () => {
  resetQueryCondition();
  getInfrastructureRelationListRun();
};

const detailDialogModel = reactive<DialogModel<InfrastructureRelation>>({
  visible: false,
  title,
  type: 'view',
  id: 0,
  change: false
});

watch(
  () => detailDialogModel.visible,
  (value: boolean) => {
    if (!value && detailDialogModel.change) {
      getInfrastructureRelationListRun();
      detailDialogModel.change = false;
    }
  }
);
</script>
<template>
  <HqContainerTable
    :base-url="urls.ndePersonCertification"
    :title="title"
    :loading="getInfrastructureRelationListLoading"
    :total="getInfrastructureRelationListData?.total"
    :table-data="getInfrastructureRelationListData?.records"
    v-model:pageSize="queryCondition.pageSize"
    v-model:current-page="queryCondition.currentPage"
    @handle-query="getInfrastructureRelationListRun"
    @handle-reset-query="handleResetQuery"
    @handle-reload="getInfrastructureRelationListRun"
    v-model:detail-dialog-model="detailDialogModel"
    :operate-column="true"
  >
    <template #search>
      <hq-col kind="search">
        <el-select
          v-model="queryCondition.addressProvince"
          filterable
          clearable
          placeholder="请选择相关方所在省"
          @change="getInfrastructureRelationListRun"
        >
          <HqProvinceOptions />
        </el-select>
      </hq-col>
      <hq-col kind="search">
        <el-input v-model="queryCondition.name" placeholder="请输入相关方名称" clearable />
      </hq-col>
    </template>

    <template #tableColumns>
      <HqTableColumn label="公司名称" prop="name" :min-width="150" />
      <HqTableColumn label="省份" prop="addressProvince" :min-width="50" />
      <HqTableColumn label="联系人" prop="linkPerson" :min-width="50" />
      <HqTableColumn label="联系电话" prop="linkPhone" :min-width="50" />
      <HqTableColumn label="电子邮箱" prop="linkEmail" :min-width="100" />
      <HqTableColumn label="开户银行" prop="openBank" :min-width="100" />
      <HqTableColumn label="银行账号" prop="bankAccount" :min-width="100" />
      <HqTableColumn label="税务登记号" prop="taxNumber" :min-width="100" />
      <HqTableColumn label="营业执照" :min-width="50">
        <template #default="{ row }">
          <el-link
            type="success"
            v-if="row.businessLicenseAttachmentUrl"
            :href="row.businessLicenseAttachmentUrl"
            target="_blank"
          >
            查看附件
          </el-link>
          <el-text v-else> 查看附件 </el-text>
        </template>
      </HqTableColumn>
    </template>
  </HqContainerTable>
  <DetailDialog v-model:dialog-model="detailDialogModel" v-if="detailDialogModel.visible" />
</template>
<style lang="scss" scoped></style>
